home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / correl_matrix.pro < prev    next >
Text File  |  1997-07-08  |  1KB  |  46 lines

  1. ; $Id: correl_matrix.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1991-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6.  
  7. function correl_matrix,X
  8. ;+
  9. ; NAME:
  10. ;    CORREL_MATRIX
  11. ;
  12. ; PURPOSE: 
  13. ;    To compute correlation coefficients of pairs of columns of X.
  14. ;
  15. ; CATEGORY:
  16. ;    Statistics.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    Result = CORREL_MATRIX(X)
  20. ;
  21. ; INPUTS: 
  22. ;    X:    Matrix of experimental data.  X(i,j) = the value of the ith
  23. ;        variable in the jth observation.
  24. ;
  25. ; OUTPUT:
  26. ;    CORREL_MATRIX returns a matrix M, where M(i,j) = the simple Pearson
  27. ;    correlation coefficient between the ith and jth variable. 
  28. ;-
  29.  N = size(X)
  30.  C = N(1)
  31.  N = N(2)
  32.  
  33. if N LT 2 THEN BEGIN
  34.   print,       $
  35.      'correl_matrix - need more than one pair of observations'
  36.   return,-1
  37. ENDIF
  38.  X = float(X)
  39.  M = Fltarr(C,C) + 1
  40.  VarXI = X - (X # Replicate(1.0/N,N)) # Replicate(1.0,N)
  41.  SS = VarXI^2 # Replicate(1.0,N) 
  42.  SS = sqrt(SS # SS)
  43.  M = (VarXI # transpose(VarXI))/SS
  44.  return,M
  45.  END
  46.